﻿using DevExpress.XtraEditors;
using System;
using System.Data;
using System.Windows.Forms;

using LDataAccess;
using LModels;
using Models;

namespace LClient
{
    public partial class frmWorkspace : XtraForm
    {
        Models.Workspace W;

        public long IDWorkspace = 0;

        public frmWorkspace()
        {
             InitializeComponent();
             W = new Factory<Workspace>(AppStaticObjects.PM.GetProxy("lidarDB")).New() as Workspace;

        }
       

        private void frmWorkspace_Load(object sender, EventArgs e)
        {

            if (IDWorkspace == 0)
            {
                // New entry layout
                btnDelete.Enabled = false;

                txtDate.Text = DateTime.Now.ToShortDateString();
                txtPlace.Focus();
                
            }
            else
            {
                W = new Factory<Workspace>(AppStaticObjects.PM.GetProxy("Lidar")).Load(IDWorkspace) as Workspace;

                txtDate.Text = W.Date.ToString();
                txtPlace.Text = W.Place;
                txtDescription.Text = W.Description;
                txtNotes.Text = W.Notes;
                
            }
        }

        private void btnQuit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Quit();
        }

        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
        }

        private void btnSaveQuit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
            Quit();
        }

        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Delete();
            Close();
        }

        private void Save()
        {

            W.Date = DateTime.Parse(txtDate.Text);
            W.Place = txtPlace.Text;
            W.Description = txtDescription.Text;
            W.Notes = txtNotes.Text;

            W.Save();
   
        }

        private void Delete()
        {
            W.Delete();
        }

        private void Quit()
        {
            // Close
            this.Close();
        }



    }
}
